package com.mall.mymall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.mymall.dao.dto.ProductDto;
import com.mall.mymall.dao.dto.QueryDto;
import com.mall.mymall.dao.dto.querypage.RefundPageRequest;
import com.mall.mymall.dao.entity.Organizations;
import com.mall.mymall.dao.entity.Refunds;
import com.mall.mymall.mapper.RefundsMapper;
import com.mall.mymall.service.RefundsService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 十里坡
 * @since 2025-03-24
 */
@Service
public class RefundsServiceImpl extends ServiceImpl<RefundsMapper, Refunds> implements RefundsService {

    @Override
    public QueryDto<Refunds> pageRefunds(RefundPageRequest refundPageRequest) {
        Page<Refunds> page = new Page<>(refundPageRequest.getPageRequestDto().getPage(), refundPageRequest.getPageRequestDto().getSize());

        // 创建条件构造器
        QueryWrapper<Refunds> queryWrapper = new QueryWrapper<>();

        // 根据 RefundPageRequest 中的条件添加查询条件
queryWrapper
        .eq(refundPageRequest.getQuery().getOrderId() != null, "order_id", refundPageRequest.getQuery().getOrderId())
        .eq(refundPageRequest.getQuery().getOrderStatus() != null && !refundPageRequest.getQuery().getOrderStatus().isEmpty(), "order_status", refundPageRequest.getQuery().getOrderStatus())
        .eq(refundPageRequest.getQuery().getRefundsId() != null, "refunds_id", refundPageRequest.getQuery().getRefundsId());



        // 执行分页查询
        IPage<Refunds> resultPage = this.page(page, queryWrapper);

        // 构造返回结果
        QueryDto<Refunds> result = new QueryDto<>();
        result.setTotal((int) resultPage.getTotal());
        result.setRecords(resultPage.getRecords());

        return result;
    }
}
